﻿using System.Collections.Generic;
using System.Data;
using Luna.Model.Common;

namespace Luna.Data.Common
{
    /// <summary>
    /// Mapper for data interface IGeolocalisationData.
    /// </summary>
    public partial class GeolocalisationDataMapper
    {
        private const string DefaultSearchRequest = "Meta.geolocalisation_search";

        private const string DistanceColumnName = "Distance";
        private const string RowsColumnName = "Rows";

        public string SearchRequest { get; set; }

        partial void Initialize()
        {
            SearchRequest = DefaultSearchRequest;
        }

        public IEnumerable<IGeolocalisationData> Search(IDbTransaction transaction, IGeoData data, double distance, int rows)
        {
            return ExecuteGetAll(
                    transaction,
                    SearchRequest,
                    c =>
                    {
                        c.AddParameter(LatitudeColumnName, data.Latitude);
                        c.AddParameter(LongitudeColumnName, data.Longitude);
                        c.AddParameter(DistanceColumnName, distance);
                        c.AddParameter(RowsColumnName, rows);
                    });
        }
    }
}